package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.base.Constant;
import com.cardbaobao.cardbabyclient.callback.RecycleItemClickedCallback;
import com.cardbaobao.cardbabyclient.model.QrCodeDebitFeeRateData;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerHolder;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;

import java.util.List;

/**
 * Created by Jiangzx on 2017/10/12 14:40.
 */

public class QrCodeDebitChannelAdapter extends CommonRecyclerAdapter<QrCodeDebitFeeRateData.FeeRate>{
    private int selected=0;

    private RecycleItemClickedCallback callback;

    public void setCallback(RecycleItemClickedCallback callback){
        this.callback=callback;
    }

    public QrCodeDebitChannelAdapter(Context context, List<QrCodeDebitFeeRateData.FeeRate> data) {
        super(context, data, R.layout.item_qr_code_channel);
    }

    @Override
    public void convert(final CommonRecyclerHolder holder, QrCodeDebitFeeRateData.FeeRate rate) {
        ImageLoaderUtil.displayImage(URLUtil.CBB_IMG_URL+rate.getPicture_path(),
                (ImageView) holder.getView(R.id.iv_channel));
        if(holder.position==selected){
            holder.getView(R.id.iv_mark).setVisibility(View.VISIBLE);
        }else{
            holder.getView(R.id.iv_mark).setVisibility(View.INVISIBLE);
        }
        TextView tvChannel=holder.getView(R.id.tv_channel);
        switch (rate.getChannel_type()){
            case Constant.KQB010102:
                //微信
                tvChannel.setText("微信");
                break;
            case Constant.KQB010103:
                //支付宝
                tvChannel.setText("支付宝");
                break;
            case Constant.KQB010104:
                //京东
                tvChannel.setText("京东");
                break;
            case Constant.KQB010105:
                //QQ
                tvChannel.setText("QQ");
                break;
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback!=null){
                    callback.onRecycleItemClicked(holder.position);
                }
            }
        });
    }

    public QrCodeDebitFeeRateData.FeeRate getSelected(){
        return mData.get(selected);
    }

    public void setSelected(int position){
        this.selected=position;
        notifyDataSetChanged();
    }
}
